<template>
  <el-select style="width: 100%;" v-model="dataValue" :disabled="disabled" filterable clearable @change="valueChange" placeholder="请选择">
    <el-option v-for="(item, index) in option" :key="index" :label="item.name" :value="item.value">
    </el-option>
  </el-select>
</template>
<script type="text/javascript">
  import stringMixin from './stringMixin'
  import {
    receivables
  } from "@/api/customermanagement/common";
  export default {
    name: 'xh-select', // 新建 select
    components: {},
    mixins: [stringMixin],
    watch: {
      contract: {
        handler(val) {
          console.log('contract')
        }
      },
      item: {
        handler(val) {
          if (val && val.data.setting) {
            var settingList = val.data.setting
            if (val.data.form_type == "receivables") {
              console.log(localStorage.getItem('title'), '调用接口')
              receivables({
                  contract_id: localStorage.getItem('contract_id'),
                  type: localStorage.getItem('title') == '新建退款申请' ? 2 : (localStorage.getItem('title') == '新建核定成本调整' ?
                    1 : 3)
                })
                .then((res) => {
                  this.option = res.data.map(item => {
                    return {
                      name: item.number,
                      value: item.receivables_id
                    }
                  })
                  //   localStorage.removeItem('title')
                  localStorage.setItem('costList', JSON.stringify(res.data))
                  console.log(res.data, 'option.data')
                })
                .catch((error) => {
                  callback(new Error(error.error ? error.error : "验证出错"));
                });
            }
            if (settingList.length > 0 && typeof settingList[0] == 'string') {
              var array = []
              for (let index = 0; index < settingList.length; index++) {
                const element = settingList[index]
                array.push({
                  name: element,
                  value: element
                })
              }
              this.option = array
              //   console.log(array, 'array')
            } else if (
              settingList.length > 0 &&
              settingList[0].status_id &&
              !settingList[0].value
            ) {
              // 商机阶段
              this.option = settingList.map((item, index, array) => {
                item.value = item.status_id
                return item
              })
            } else {
              this.option = settingList

            }
          } else {
            this.option = []
          }
        },
        deep: true,
        immediate: true
      }
    },
    computed: {},
    data() {
      return {
        option: []
      }
    },
    props: {},
    mounted() {},
    methods: {

    }
  }

</script>
<style lang="scss" scoped>
</style>
